package com.stageadminserver.adminserver.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.stageadminserver.adminserver.mapper.DemandFormatMapper;
import com.stageadminserver.adminserver.service.DemandFormatService;
import com.stagecommon.common.pojo.DemandFormat;
import com.stagecommon.common.pojo.RespBean;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author: yxl
 * @since: 2022-04-24
 **/
@Service
@Slf4j
public class DemandFormatServiceImpl extends ServiceImpl<DemandFormatMapper, DemandFormat> implements DemandFormatService {

    @Autowired
    private DemandFormatMapper demandFormatMapper;

    @Override
    public RespBean<IPage> getFormatByPage(Integer currentPage, Integer size, DemandFormat demandFormat) {
        Page<DemandFormat> page = new Page<>(currentPage, size);
        return RespBean.operationSuccess("查询需求成功！", 200, demandFormatMapper.selectFormatByPage(page, demandFormat.getName()));

    }

    @Override
    public RespBean<DemandFormat> getFormatById(Integer demandFormatId) {
        return RespBean.operationSuccess("查询需求成功！", 200, demandFormatMapper.selectFormatById(demandFormatId));
    }

    @Override
    public RespBean<Integer> updateFormatById(DemandFormat demandFormat) {
        if (demandFormatMapper.updateById(demandFormat) == 1) {
            return RespBean.operationSuccess("更新需求格式成功！",200,1);
        }
        return RespBean.operationFail("更新需求格式失败！");
    }

    @Override
    public RespBean<Integer> addFormat(DemandFormat demandFormat) {
        if (demandFormatMapper.insert(demandFormat) == 1){
            return RespBean.operationSuccess("添加需求格式成功!", 200, 1);
        } else {
            return RespBean.operationFail("添加需求格式失败！");
        }
    }

    @Override
    public RespBean<Integer> deleteFormatById(DemandFormat demandFormat) {
        if (demandFormatMapper.deleteById(demandFormat.getDemandFormatId()) == 1){
            return RespBean.operationSuccess("删除需求格式成功！", 200, 1);
        } else
            return RespBean.operationFail("删除需求失败！");
    }
}
